#!/bin/sh

# Makes a patch by shar'ing up a directory (given as an argument) and prefixing 
# patch-hdr to an output file (given as the second argument)

PATCHDIR=$1
OUTPUT=$2
INSTALL=$PATCHDIR/install.sh

usage(){
  echo Usage:
  echo "$0 <dirname> <output>-- where <dirname> contains an install.sh file"
  exit 1
}

if [ -z "$OUTPUT" ]
then 
  echo Need an output filename
  usage
fi

if [ -e $INSTALL ]
then

  SHARNAME=patch.$$
  trap 'rm -f $SHARNAME; exit 1' HUP INT QUIT TERM

  echo Writing to $SHARNAME
  (cd $PATCHDIR; shar *) > $SHARNAME
  cat patch-hdr $SHARNAME > $OUTPUT
  rm $SHARNAME
  
  echo Done
else
  usage
fi
